package com.jxstyle.core.base;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxstyle.core.common.page.PageInfo;

public class BaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M, T>{
	
	public PageInfo<T> page(PageInfo<T> page) {
        return this.page(page, Wrappers.<T>emptyWrapper());
    }
	public PageInfo<T> page(PageInfo<T> page, Wrapper<T> queryWrapper) {
		Page<T> p = new Page<>(page.getCurrent(), page.getSize());
		IPage<T> ipage = super.page(p, queryWrapper);
		page.setRecords(ipage.getRecords());
		page.setTotal(ipage.getTotal());
        return page;
    }
	public PageInfo<Map<String, Object>> pageMaps(PageInfo<T> page, Wrapper<T> queryWrapper) {
		Page<T> p = new Page<>(page.getCurrent(), page.getSize());
		IPage<Map<String, Object>> selectMapsPage = super.pageMaps(p, queryWrapper);
        return new PageInfo<>(selectMapsPage);
    }
}
